package com.sec.android.app.myfiles.util;

import android.content.Context;

import com.sec.android.app.myfiles.MyFilesTestRunner;
import com.sec.android.app.myfiles.TestInput;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;

/**
 * Created by jaebae on 2016-06-10.
 */
@RunWith(MyFilesTestRunner.class)
public class testDrmUtils {
    Context mContext;

    @Before
    public void setUp() throws Exception {
        mContext = RuntimeEnvironment.application;
    }

    @Test
    public void testIsDcfFile() {
        TestInput[] testList = TestInput.createTestData(
                new TestInput<>(true, "/test.dcf"),
                new TestInput<>(true, "/test.DCF"),
                new TestInput<>(false, "/test_DCF"),
                new TestInput<>(false, "/test_DCF.mp3")
        );

        for (TestInput testValue : testList) {
            boolean actual = DrmUtils.isDcfFile((String) testValue.get(0));
            Assert.assertEquals(testValue.expected(), actual);
        }
    }

    @Test
    public void testIsOMADrmFile() {
        TestInput[] testList = TestInput.createTestData(
                new TestInput<>(true, "/test/drm.dcf"),
                new TestInput<>(false, "/test/normal.dcf"),
                new TestInput<>(false, "/test/normal.txt")
        );

        for (TestInput testValue : testList) {
            boolean actual = DrmUtils.isOMADrmFile(mContext, (String) testValue.get(0));
            Assert.assertEquals(testValue.expected(), actual);
        }
    }

    @Test
    public void testGetRealMimeTypeOfDRM() {
        TestInput[] testList = TestInput.createTestData(
                new TestInput<String>(null, null),
                new TestInput<>("audio/*", "/drm_audio.dcf"),
                new TestInput<>("video/*", "/drm_video.dcf"),
                new TestInput<>("image/*", "/drm_image.dcf"),
                new TestInput<>("", "/drm_test.dcf")
        );

        for (TestInput testValue : testList) {
            String actual = DrmUtils.getRealMimeTypeOfDRM(mContext, (String) testValue.get(0));
            Assert.assertEquals(testValue.expected(), actual);
        }
    }

    @Test
    public void testIsPlayReadyFile() {
        TestInput<Boolean>[] testList = TestInput.createTestData(
                new TestInput<>(false, null),
                new TestInput<>(false, "/test/test.dcf"),
                new TestInput<>(false, "/test/test.wma"),
                new TestInput<>(false, "/test/test.wmv"),
                new TestInput<>(false, "/test/test.pyv"),
                new TestInput<>(false, "/test/test.pya"),
                new TestInput<>(false, "/test/drm_test.dcf"),
                new TestInput<>(true, "/test/drm_test.wma"),
                new TestInput<>(true, "/test/drm_test.wmv"),
                new TestInput<>(true, "/test/drm_test.pyv"),
                new TestInput<>(true, "/test/drm_test.pya")

        );

        for (TestInput<Boolean> testValue : testList) {
            Boolean actual = DrmUtils.isPlayReadyFile(mContext, (String) testValue.get(0));
            Assert.assertEquals((String) testValue.get(0), testValue.expected(), actual);
        }
    }


    @Test
    public void testIsForwardable() {
        TestInput<Boolean>[] testList = TestInput.createTestData(
                new TestInput<>(false, null),
                new TestInput<>(true, "/test/test.wma"),
                new TestInput<>(true, "/test/test.wmv"),
                new TestInput<>(false, "/test/drm_test.wma"),
                new TestInput<>(false, "/test/drm_test.wmv"),
                new TestInput<>(true, "/test/test.dcf"),
                new TestInput<>(true, "/test/drm_test.dcf"),
                new TestInput<>(false, "/test/fl_drm_test.dcf")

        );

        for (TestInput testValue : testList) {
            Boolean actual = DrmUtils.isForwardable(mContext, (String) testValue.get(0));
            Assert.assertEquals((String) testValue.get(0), testValue.expected(), actual);
        }
    }

    @Test
    public void testIsDRMFile() {
        TestInput<Boolean>[] testList = TestInput.createTestData(
                new TestInput<>(false, null),
                new TestInput<>(false, "/test/test.wma"),
                new TestInput<>(false, "/test/test.wmv"),
                new TestInput<>(false, "/test/test.dcf"),
                new TestInput<>(false, "/test/fl_drm_test.jpg"),

                new TestInput<>(true, "/test/drm_test.wma"),
                new TestInput<>(true, "/test/drm_test.wmv"),
                new TestInput<>(true, "/test/drm_test.dcf"),
                new TestInput<>(true, "/test/fl_drm_test.dcf")
        );

        for (TestInput testValue : testList) {
            Boolean actual = DrmUtils.isDRMFile(mContext, (String) testValue.get(0));
            Assert.assertEquals((String) testValue.get(0), testValue.expected(), actual);
        }
    }


}

